package com.hongtu.supplychain.finance.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by huangchuan on 2017/4/20.
 * 正则表达式验证
 */
public class PatternUtil {

    private final static String MOBILE_REGULAR = "^1[0-9]{10}$";

    private final static String IDCARD_REGULAR = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)";

    private final static String VEHICLE_NO_REGULAR = "^[\\u4e00-\\u9fa5]{1}[A-Za-z]{1}[A-Za-z0-9]{5}$";

    private final static String LOAD_WEIGHT_REGULAR = "^(([1-9][0-9]{0,2})([.][0-9]?[0-9]{1})?)$|^([0][.](([0-9]?[1-9]{1})?|([1-9]?[0]))?)$";

    /**
     * 非法字符验证规则
     */
    private final static String ILLEGAL_REGULAR = "[~!@#$^&*\\(\\)=\\|\\{\\}':;',\\/\\\\\\[\\].<>\\?~！@#￥……&*（）—【】‘；：”“'。，、？]+";

    /**
     * 空格验证
     */
    private final static String EMPTY_REGULAR = "\\s+";

    /**
     * 手机号验证
     */
    public static boolean validateMobile(String mobile) {
        return validate(MOBILE_REGULAR, mobile);
    }


    private static boolean validate(String regular, String string) {
        Pattern pattern = Pattern.compile(regular);
        Matcher matcher = pattern.matcher(string);
        if(!matcher.matches()){
            return false;
        }
        return true;
    }
}
